package com.zfl.controller;

import com.zfl.pojo.Result;
import com.zfl.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


import java.util.UUID;

@RestController
@RequestMapping("/file")
public class FileUploadController {


    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID() + originalFilename;
        String url = AliOssUtil.uploadFile(filename, file.getInputStream());
        return Result.success(url);

        /**
        //文件存储到本地磁盘
        String originalFilename = file.getOriginalFilename();
        //保证文件的名字是唯一的,防止文件覆盖
        String filename = UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
        file.transferTo(new File("C:\\Users\\ZFrankLin\\Desktop\\files\\" + filename));
        return Result.success("C:\\Users\\ZFrankLin\\Desktop\\files\\" + filename);
         */
    }
}
